using Fawcett.Plugins;
using System.Timers;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Windows.Forms;

namespace Fawcett.Plugins.Custom
{
	/// <summary>
	/// This class implements the IPlugin interface
	/// to provide the ability to parse and isolate email addresses found within
	/// the current editor's text
	/// </summary>
    public class ControlFSX : CPlugin
    {
      
        private RibbonButton btnPause = new System.Windows.Forms.RibbonButton();
        public ControlFSX()
        {
        }


        private void selected()
        {
            if (btnPause.Checked == true)
            {
                btnPause.Image = Resources.Pause.ToBitmap();
            }
            else
            {
                btnPause.Image = Resources.Public.ToBitmap();
            }
        }

        public override RibbonTab SetupMenu( RibbonTab HomeTab)
        {
            RibbonTab NewTab = new System.Windows.Forms.RibbonTab(Name);
            RibbonPanel AddonPanel = new RibbonPanel("Pause"); ;

            selected();


            btnPause.Click += new EventHandler(this.Pause);

            AddonPanel.ButtonMoreEnabled = false;
            AddonPanel.ButtonMoreVisible = false;

            AddonPanel.Items.Add(btnPause);

            NewTab.Panels.Add(AddonPanel);

            return NewTab;
        }

        public void Pause(Object sender,  EventArgs fe)
        {
            RibbonButton btn =  (RibbonButton)sender;

            GlobalEvent.FireEvent(this, new EPlugin(PluginCode.TO_FSX, "FSX_SETPAUSE",  ! btn.Checked  ));

            selected();
        }

        public override void PluginEventHandler(object sender, EPlugin p)
        {
            Console.WriteLine("FSCUIP {0}", p.GetInfo );

            if( p.GetInfo == "FSX_GETPAUSE" )
            {
                Console.WriteLine("Caught Pause {0}", p.GetValue);
                this.btnPause.Checked = ( p.GetValue == 0) ? false : true;
                selected();
            }
        }
    }
}
